package com.cskaoyan.service.admin.comment.impl;

import com.cskaoyan.bean.MarketComment;
import com.cskaoyan.bean.MarketCommentExample;
import com.cskaoyan.bean.bo.admin.comment.ListBO;
import com.cskaoyan.bean.vo.admin.comment.ListforCommentVO;
import com.cskaoyan.mapper.MarketCommentMapper;
import com.cskaoyan.service.admin.comment.CommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mr.Tang
 * @since 2022/09/08 19:10
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    MarketCommentMapper marketCommentMapper;

    @Override
    public ListforCommentVO listForComment(ListBO listBO) {
        PageHelper.startPage(listBO.getPage(),listBO.getLimit());
        MarketCommentExample marketCommentExample = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = marketCommentExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        marketCommentExample.setOrderByClause(listBO.getSort()+" "+listBO.getOrder());
        // 判断条件
        Integer userId = listBO.getUserId();
        Integer valueId = listBO.getValueId();
        if(userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if(valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }

        List<MarketComment> marketCommentsList = new ArrayList<>();
        marketCommentsList = marketCommentMapper.selectByExample(marketCommentExample);
        PageInfo<MarketComment> marketCommentPageInfo = new PageInfo<>(marketCommentsList);

        return ListforCommentVO.data(marketCommentPageInfo);
    }

    @Override
    public void deleteForComment(MarketComment marketComment) {
        marketComment.setDeleted(true);
        marketCommentMapper.updateByPrimaryKeySelective(marketComment);
    }


    /**
     * 删除商品
     */

}
